package graph_viewer.util;

import java.awt.Graphics;
import java.awt.FontMetrics;
import java.awt.Font;
import java.util.ArrayList;
import java.util.Iterator;

import graph_viewer.drawer.*;
import graph_viewer.structure.*;
import graph_viewer.structure.clustering.*;
import graph_viewer.layout.*;

public class Clustering_Util{
	static public boolean has_pseudo_child( Node node ){
		for ( Iterator _i=node.get_children().iterator(); _i.hasNext() ; ){
			Node child	= (Node)_i.next();

			if ( child.get_is_psuedo() ){
				//Debug.println( node + " has a psuedo ndoe " + child, 25 );
				return true;
			}
		}

		return false;	
	}
	
	static public void remove_pseudo_child( Graph g, Node node ){
		ArrayList		current_children					= node.get_children();
		Node		pseudo_child						= find_psuedo_child( node );
		ArrayList		children_under_pseudo_child			= pseudo_child.get_children();
		
		//remove psuedo node from node
		current_children.remove( pseudo_child );
	
		//remove psuedo node from graph		
		g.delete_node( pseudo_child );

		for ( Iterator _i = children_under_pseudo_child.iterator(); _i.hasNext(); ){
			Node child	= (Node)_i.next();
			child.set_parent( node );
			current_children.add( child );
		}	
	}
	
	static public Node find_psuedo_child( Node node ){		
		for ( Iterator _i = node.get_children().iterator(); _i.hasNext(); ){
			Node child	= (Node)_i.next();

			if ( child.get_is_psuedo() ){
				return child;
			}
		}

		return null;
	}

}//:~
